#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define D long double
#define int long long 
#define mod 1000000007
#define N 10004
int dp[N][N][2][2],g[N][N][2][2],in[N][N][2][2],a[N],b[N],c[N],t[N];int n,k,p2[N];
int dfs(int x,int v,int zt,int lim){
	if(v<=-1)	return 0;
	if(x==n){
		dp[x][v][zt][lim]=(v==0);return (v==0);
	}
	if(dp[x][v][zt][lim]!=-1)	return dp[x][v][zt][lim];
	int ans=0,up=1;
	if(lim)	up=t[x+1];
	for(int i=0;i<=up;i++){
		ans+=dfs(x+1,v-((i!=a[x+1])^zt),(i!=a[x+1]),lim&(i==up));ans%=mod;
	}
	dp[x][v][zt][lim]=ans;return ans;
}
struct node{
	int x,v,zt,lim;
};
void dp_g(int x,int v,int zt,int lim){
	queue<node> q;memset(g,0,sizeof(g));memset(in,0,sizeof(in));
	g[x][v][zt][lim]=1;
	for(int i=0;i<n;i++){//x
		for(int j=0;j<=k;j++){//v
			for(int l=0;l<=1;l++){//zt
				for(int tt=0;tt<=1;tt++){//lim
					int up=1;
					if(tt)	up=t[i+1];
					for(int ti=0;ti<=up;ti++){//i
						if((j-((ti!=a[i+1])^l))>=0){
							in[i+1][(j-((ti!=a[i+1])^l))][ti!=a[i+1]][tt&(ti==up)]++;
						}
					}
				}
			}
		}
	}
	for(int i=0;i<n;i++){//x
		for(int j=0;j<=k;j++){//v
			for(int l=0;l<=1;l++){//zt
				for(int tt=0;tt<=1;tt++){//lim
					if(!in[i][j][l][tt])	q.push({i,j,l,tt});
				}
			}
		}
	}
	while(q.size()){
		int x=q.front().x,v=q.front().v,zt=q.front().zt,lim=q.front().lim;q.pop();
		//cerr<<"NOW: "<<x<<" "<<v<<" "<<zt<<" "<<lim<<" : "<<g[x][v][zt][lim]<<endl;
		if(x==n)	continue;
		int up=1;
		if(lim)	up=t[x+1];
		for(int i=0;i<=up;i++){
			if((v-((i!=a[x+1])^zt))>=0){
				g[x+1][v-((i!=a[x+1])^zt)][i!=a[x+1]][lim&(i==up)]+=g[x][v][zt][lim];
				g[x+1][v-((i!=a[x+1])^zt)][i!=a[x+1]][lim&(i==up)]%=mod;
				if(!(--in[x+1][v-((i!=a[x+1])^zt)][i!=a[x+1]][lim&(i==up)])){
					q.push({x+1,v-((i!=a[x+1])^zt),(i!=a[x+1]),lim&(i==up)});
				}
			}
		}
	}
}
int getans(int tmp[1003]){
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<=n;i++)	t[i]=tmp[i];
	int ans=0;
	dfs(0,k,0,t[0]);ans+=p2[n]*dp[0][k][0][t[0]]%mod;ans%=mod;
	dp_g(0,k,0,t[0]);
	for(int i=1;i<=n;i++){
		int sum=0;
		for(int j=0;j<=k;j++){
			for(int z=0;z<=1;z++){
				if(dp[i][j][a[i]^1][z]!=-1)
				sum+=max(0ll,dp[i][j][a[i]^1][z]*g[i][j][a[i]^1][z]%mod);sum%=mod;
			}
		}
		//cerr<<"NOW: "<<i<<" "<<sum<<endl;
		ans+=p2[n-i]*sum%mod;ans%=mod;
	}
	memset(dp,-1,sizeof(dp));
	dfs(0,k,1,t[0]);ans+=p2[n]*dp[0][k][1][t[0]]%mod;ans%=mod;
	dp_g(0,k,1,t[0]);
	for(int i=1;i<=n;i++){
		int sum=0;
		for(int j=0;j<=k;j++){
			for(int z=0;z<=1;z++){
				sum+=max(0ll,dp[i][j][a[i]^1][z]*g[i][j][a[i]^1][z]%mod);sum%=mod;
			}
		}
		//cerr<<"NOW2: "<<i<<" "<<sum<<endl;
		ans+=p2[n-i]*sum%mod;ans%=mod;
	}
	return ans;
}
signed main(){
	freopen("lost.in","r",stdin);
	freopen("lost.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	p2[0]=1;
	for(int i=1;i<=1000;i++)	p2[i]=p2[i-1]*2%mod;
	cin>>n>>k;n--;a[0]=1;
	for(int i=1;i<=n;i++){
		char c;cin>>c;a[i]=(c=='R');
	}
	string s;cin>>s;
	if(s.size()==(n+1)){
		for(int i=0;i<=n;i++)	b[i]=s[i]-'0';
	}
	cin>>s;
	if(s.size()!=(n+1)){
		cout<<"0";return 0;
	}
	for(int i=0;i<=n;i++)	c[i]=s[i]-'0';
	if(b[0]){
		b[n]--;
		for(int i=n;i>=1;i--){
			if(b[i]>=0)	break;
			b[i]=1;b[i-1]--;
		}
	}
	cout<<((getans(c)-getans(b))%mod+mod)%mod;
	return 0;
}

